<template>
  <div>
    <el-switch v-model="confirmed" class="ml-2" inline-prompt active-text="二次验证已开启" inactive-text="二次验证已关闭"
      @change="changeCon" />
    <div class="flex items-center">
      <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/QR_code_of_Chinese_Wikipedia_main_page_20131019.svg"
        class="size-200px" />
      <div class="flex flex-col flex-1 pl20px">
        <span>sdassdadas</span>
        <span>sdassdadas</span>
        <span>sdassdadas</span>
        <span>sdassdadas</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import Api from '@/api/auth'
import { onMounted } from 'vue'

const confirmed = ref(false)
const getAuthType = async () => {
  const data = await Api.pwdStatus()
  console.log(data);
  confirmed.value = data.confirmed
  if (data.confirmed) {
    getCodeKey()
  }
}
// 密码验证
const switchTwo = async () => {
  const data = await Api.switchTwo()
  console.log(data);
}
// 密码验证弹窗
const changeCon = async () => {
  ElMessageBox.prompt('请输入登陆密码', t('hint.1')).then(({ value }) => {
    Api.confirmPassword({ password: value }).then(s => {
      console.log('dddddddddd', s);
      openTwo()
    }).finally(() => {
      // getAuthType()
    })
  }).catch(() => {
    getAuthType()
  })
}
//  获取二维码和恢复码
const getCodeKey = async () => {
  const codeData = await Api.twoQrCode()
  const keyData = await Api.twoKey()
  console.log(codeData, keyData);
}
//开启关闭
const openTwo = async () => {
  if (confirmed.value) {
    const data = await Api.switchTwo()
    console.log('openTwo', data);
    getCodeKey()
  } else {
    const data = await Api.delTwo()
    console.log('delTwo', data);
  }
}
onMounted(() => {
  getAuthType()
})
</script>

<style></style>